package com.zhuhjay.common.core.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

/**
 * @author ZhuHJay
 * @date 2023/8/18 10:03
 */
@Configuration
public class CaffeineCacheConfig {

    /**
     * 用户信息缓存配置
     */
    @Bean
    public Cache<Integer, Object> userInfoCache() {
        return Caffeine.newBuilder()
                // 写入或更新后 5 分钟过期
                .expireAfterWrite(Duration.ofMinutes(5))
                .maximumSize(100)
                // 设置为软引用
                .softValues()
                .build();
    }

}
